﻿using System;
using System.Collections.Generic;
using System.Text;
using Torch.WL.Business.Interface;
using Torch.FrameWork.Utility;
using Torch.WL.Entity.CleanChina;
using Torch.WL.Business.CleanChina;

namespace Torch.WL.Business
{
    public class NewsDetailProvider : BaseProvider<NewsDetailProvider.RequestDataInfo>, IDataProvider
    {
        public NewsDetailProvider(string _jsonInfo)         : base(_jsonInfo)
        {

        }

        public IMessageInfo Do()
        {
            message.data = ProcessResponseData();
            return message;
        }

        private ResponseDataInfo ProcessResponseData()
        {
            //use postdata.data to process responseData
            if (postdata == null || postdata.data == null)
            {
                message.code = (int)MessageCodeType.WrongRequestPara;
                message.message = Utils.GetEnumDescription(MessageCodeType.WrongRequestPara);
                return null;
            }
            
            TbNewsEntity entity = TbNewsManager.Instance().GetModelByCache(postdata.data.news_id);
            if (entity == null)
            {
                return null;
            }


            ResponseDataInfo responseData = new ResponseDataInfo();
            responseData.news_id = entity.newsId;
            responseData.news_title = entity.title;
            responseData.news_date = entity.newsDate.ToString("yyyy-MM-dd");
            responseData.news_content = entity.content;
            if (entity.contentImg.Length>0)
                responseData.news_img = ConfigHelper.GetConfigString("WebsiteImageUrl") + entity.contentImg;
            else
                responseData.news_img = "";

            return responseData;

         
        }

        public class RequestDataInfo 
        {
            public int news_id { get; set; }
        }

        public class ResponseDataInfo
        {
            public int news_id { get; set; }
            public string news_title { get; set; }
            public string news_date { get; set; }
            public string news_content { get; set; }
            public string news_img { get; set; }            

        }

    }
}
